package com.atguigu.demojuc.chap09;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author njg
 * @version 1.0
 * @date 2025/6/18 20:19
 */
class DataOne{
    /*private static Integer num = 0;

    public synchronized  Integer increment(){
        return ++num;
    }*/
    private static AtomicInteger atomicInteger = new AtomicInteger(0);
    public int increment(){
        return atomicInteger.incrementAndGet();
    }
}
public class VolatileAtomicDemo {
    public static void main(String[] args) {
        DataOne d = new DataOne();


        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                Integer increment = d.increment();
                System.out.println(increment);
            }, "A").start();
        }
    }
}
